//
//  Factory.m
//  CToolBox
//
//  Created by crj on 16/8/4.
//  Copyright © 2016年 oyf. All rights reserved.
//

#import "Factory.h"

@implementation Factory

#pragma mark - 基础 工厂方法

+(UIButton *)btnWithFrame:(CGRect)frame
                     type:(UIButtonType)type
                    title:(NSString *)title
                 fontSize:(CGFloat)fontSize
               titleColor:(UIColor *)titleColor
          backgroundColor:(UIColor *)backgroundColor
                   target:(id)target
                 selector:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:type];
    [btn setFrame:frame];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:fontSize]];
    [btn setBackgroundColor:backgroundColor];

    [btn addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];

    return btn;
}

#pragma mark - UILabel
//单行
+(UILabel *)labelWithFram:(CGRect)frame
                     text:(NSString *)text
                 fontSize:(CGFloat)fontSize
                textColor:(UIColor *)textcolor
                    align:(NSTextAlignment)align{

    UILabel * label = [[UILabel alloc]initWithFrame:frame];
    label.text = text;
    label.numberOfLines = 1;
    label.font = [UIFont systemFontOfSize:fontSize];
    label.textColor =textcolor;
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = align;
    
    return label;

}
//多行
+(UILabel *)labelWithFram:(CGRect)frame
                     text:(NSString *)text
                 fontSize:(CGFloat)fontSize
                textColor:(UIColor *)textcolor
                  bgColor:(UIColor *)bgColor
                    align:(NSTextAlignment)align
                lineSpace:(CGFloat)lineSpace
{
    
    UILabel * label = [[UILabel alloc]initWithFrame:frame];
    label.text = text;
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:fontSize];
    label.textColor =textcolor;
    label.backgroundColor = bgColor;
    label.textAlignment = align;
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    [paragraphStyle setLineSpacing:lineSpace];//调整行间距
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    label.attributedText = attributedString;
    
    return label;
}

#pragma mark - UITextField

+(UITextField *)textFieldWithFrame:(CGRect)frame
                               Tag:(int)tag
                          BackgroundColor:(UIColor *)backgroundColor
                       Placeholder:(NSString *)placeholder
              ClearsOnBeginEditing:(BOOL)clearsOnBeginEditing
                   ClearButtonMode:(UITextFieldViewMode)clearButtonMode
                      KeyboardType:(UIKeyboardType)keyboardType
                     ReturnKeyType:(UIReturnKeyType)returnKeyType
                   SecureTextEntry:(BOOL)secureTextEntry
{
    
    UITextField *field = [[UITextField alloc]initWithFrame:frame];
    field.tag = tag;
    field.backgroundColor = backgroundColor;
    field.placeholder = placeholder;
    field.clearsOnBeginEditing = clearsOnBeginEditing;
    field.clearButtonMode = clearButtonMode;
    field.keyboardType = keyboardType;
    field.returnKeyType = returnKeyType;
    field.secureTextEntry = secureTextEntry;
    return field;
}

#pragma mark - UITableView

+ (UITableView *)tableViewWithFrame:(CGRect)frame
                           delegate:(id)delegate
                         dataSource:(id)dataSource  {
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:frame];
    tableView.showsVerticalScrollIndicator = NO;
    tableView.showsHorizontalScrollIndicator = NO;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.delegate = delegate;
    tableView.dataSource = dataSource;
    tableView.tableFooterView = [UIView new];
    
    return tableView;
}

+ (UIView *)viewWithFrame:(CGRect)frame
          backgroundColor:(UIColor *)backgroundColor
                      tag:(NSInteger)tag{
    
    UIView *view = [[UIView alloc] init];
    view.frame = frame;
    view.backgroundColor = backgroundColor;
    view.tag = tag;
    return view;
}


#pragma mark - UIAlertController

+(void)alertMessage:(NSString *)message present:(id)present
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alert addAction:alertAction];
    [present presentViewController:alert animated:YES completion:nil];
    
}


+(void)alertMessageTwoAction:(NSString *)title andMessage:(NSString *)message andAction:(void(^)(UIAlertAction *action))action present:(id)present
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *alertAction1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:action];
    [alert addAction:alertAction];
    [alert addAction:alertAction1];
    [present presentViewController:alert animated:YES completion:nil];
}

#pragma mark - 自定义UI

+(UIButton *)btnWithFrame:(CGRect)frame
                    title:(NSString *)title
                   target:(id)target
                 selector:(SEL)sel
{
    return [self btnWithFrame:frame
                         type:UIButtonTypeCustom
                        title:title
                     fontSize:15
                   titleColor:[UIColor whiteColor]
              backgroundColor:HEXCOLOR(kColorBlue1, 1)
                       target:target
                     selector:sel];
    
}


+(UITextField *)textFieldWithFrame:(CGRect)frame
                       Placeholder:(NSString *)placeholder
                     ReturnKeyType:(UIReturnKeyType)returnKeyType
{
    
    return [self textFieldWithFrame:frame
                                Tag:1000
                    BackgroundColor:[UIColor whiteColor]
                        Placeholder:placeholder
               ClearsOnBeginEditing:NO
                    ClearButtonMode:UITextFieldViewModeWhileEditing
                       KeyboardType:UIKeyboardTypeDefault
                      ReturnKeyType:returnKeyType
                    SecureTextEntry:NO];
}





@end
